#!/usr/bin/env python

from abstractPuzzle import abstractPuzzle
import os
from google.appengine.ext.webapp import template
import logging
class standardPuzzle(abstractPuzzle):
    "A standard puzzle interface, with answer submission and such"
    override_html = ""
    def puzzle_get(self,handler):
        values = {"puzzle":self.render(),"incorrect":False,"warn":self.warn_not_logged_in(),"url":handler.request.url,"override":self.override_html}
        path = os.path.join(os.path.dirname(__file__), 'standardPuzzle.html')
        handler.response.out.write(template.render(path, values))
    def puzzle_post(self,handler):
        answer = handler.request.get("answer")
        if self.check(answer):
            logging.info("correct!")
            self.solved(1.0)
            handler.redirect("/")
        else:
            values = {"puzzle":self.render(),"incorrect":True,"warn":self.warn_not_logged_in(),"url":handler.request.url,"override":self.override_html}
            path = os.path.join(os.path.dirname(__file__), 'standardPuzzle.html')
            handler.response.out.write(template.render(path, values))